home *** CD-ROM | disk | FTP | other *** search
/ The SelectWare System Volume 5 #4 / The SelectWare System Volume 5 #4.iso / bor10012 / rtsmp.pak / OVLOOPS.C < prev    next >
C/C++ Source or Header  |  1992-06-10  |  6KB  |  172 lines

  1. // Borland ObjectVision -- (C) Copyright 1991,1992 by Borland International
  2.  
  3. /*
  4.     Build OVLOOPS.DLL with a command such as this:
  5.  
  6.         icc /Ge- /Gm+ /Ss+ ovloops.c ovloops.def
  7. */
  8.  
  9. #include <os2.h>
  10. #include <string.h>
  11.  
  12. typedef PCHAR APIENTRY OVCALLBACK_GET           ( PCHAR );
  13. typedef void  APIENTRY OVCALLBACK_PUT           ( PCHAR, PCHAR );
  14. typedef PCHAR APIENTRY OVCALLBACK_EXECUTESTRING ( PCHAR, PCHAR, unsigned,
  15.     unsigned );
  16.  
  17.  
  18. /******************************************************************************
  19. *
  20. * name          SelfRegister -- Register all of the functions of this DLL
  21. *
  22. * arguments     1.  OVCALLBACK_EXECUTESTRING lpfnCallBack -- callback fn
  23. *
  24. * return        Zero
  25. *
  26. * register      @REGISTER("@REGISTER_OVLOOPS","In","","ovloops.dll",
  27. *                   "SelfRegister",1)
  28. *
  29. ******************************************************************************/
  30.  
  31. int EXPENTRY SelfRegister( OVCALLBACK_EXECUTESTRING lpfnCallBack )
  32. {
  33.     (void)(*lpfnCallBack)(
  34.         "@REGISTER(\"@WHILELOOP\",\"ICCn\",\"\"\"ConditionExpression\"\","
  35.             "\"\"ActionExpression\"\"\",\"ovloops.dll\",\"iWhileLoop\",1)"
  36.         , 0, 0, 0 );
  37.     (void)(*lpfnCallBack)(
  38.         "@REGISTER(\"@WHILEFIELD\",\"JCCwx\",\"\"\"ConditionField\"\","
  39.             "\"\"EventField\"\"\",\"ovloops.dll\",\"lWhileField\",1)"
  40.         , 0, 0, 0 );
  41.     (void)(*lpfnCallBack)(
  42.         "@REGISTER(\"@EXECUTE\",\"CCnF\",\"\"\"CommandToExecute\"\"\","
  43.             "\"ovloops.dll\",\"szExecuteString\",1)"
  44.         , 0, 0, 0 );
  45.     return 0;
  46. }
  47.  
  48. /******************************************************************************
  49. *
  50. * name          iWhileLoop -- While function using ExecuteString callback
  51. *
  52. * description   You can use this function to implement an @WHILELOOP in OV.
  53. *               Link error reporting is disabled during both condition and
  54. *               action execution.
  55. *
  56. * arguments     1.  PCHAR szCondition -- the condition expression
  57. *               2.  PCHAR szAction -- the action expression
  58. *               3.  OVCALLBACK_EXECUTESTRING lpfnCallBack -- callback fn
  59. *
  60. * return        Zero (an int)
  61. *
  62. * register      @REGISTER("@WHILELOOP","ICCn",
  63. *                   """ConditionExpression"",""ActionExpression""",
  64. *                   "ovloops.dll","iWhileLoop",1)
  65. *
  66. ******************************************************************************/
  67.  
  68. int EXPENTRY iWhileLoop(
  69.     PCHAR szCondition,
  70.     PCHAR szAction,
  71.     OVCALLBACK_EXECUTESTRING lpfnCallBack )
  72. {
  73.     char sBuf[10];
  74.     char * szConditionResult;
  75.  
  76.     szConditionResult = (*lpfnCallBack)( szCondition, sBuf, sizeof(sBuf), 1 );
  77.     while ( szConditionResult && !strcmp(szConditionResult,"Yes") )
  78.     {
  79.         (void)(*lpfnCallBack)( szAction, (PCHAR)0, 0, 1 );
  80.         szConditionResult = (*lpfnCallBack)( szCondition, sBuf,
  81.                                                  sizeof(sBuf), 1 );
  82.     }
  83.     return 0;
  84. }
  85.  
  86. /******************************************************************************
  87. *
  88. * name          lWhileField --  While function using only Get & Put callbacks
  89. *
  90. * description   You can use this function to implement an @WHILEFIELD in OV.
  91. *
  92. * arguments     1.  PCHAR szConditionField
  93. *               2.  PCHAR szEventField
  94. *               3.  OVCALLBACK_PUT lpfnPutCallBack
  95. *               4.  OVCALLBACK_GET lpfnGetCallBack
  96. *
  97. * return        unsigned long -- the number of times through the loop
  98. *
  99. * register      @REGISTER("@WHILEFIELD","JCCwx","""ConditionField"",
  100. *                   ""EventField""","ovloops.dll","lWhileField",1)
  101. *
  102. ******************************************************************************/
  103.  
  104. unsigned long EXPENTRY lWhileField(
  105.     PCHAR szConditionField,
  106.     PCHAR szEventField,
  107.     OVCALLBACK_PUT lpfnPutCallBack,
  108.     OVCALLBACK_GET lpfnGetCallBack  )
  109. {
  110.     char * szCondition;
  111.     char * szEvent;
  112.     char sNumber[20];
  113.     unsigned long lLoop;
  114.  
  115.     szCondition = (*lpfnGetCallBack)( szConditionField );
  116.     szEvent = (*lpfnGetCallBack)( szEventField );
  117.     if ( szCondition == 0 || szEvent == 0 )
  118.     {
  119.         // One of the fields doesn't exists. Don't event try because
  120.         // the while would loop forever.
  121.         lLoop = 0;
  122.     }
  123.     else
  124.     {
  125.         lLoop = 0;
  126.         while ( strcmp(szCondition,"No") )
  127.         {
  128.             lLoop++;
  129.             sprintf(sNumber,"%ld",lLoop);
  130.             if ( lLoop == 1 && !strcmp(szEvent,sNumber) )
  131.             {
  132.                 strcpy( sNumber, "0" ); // To ensure we get a change event
  133.             }
  134.             (*lpfnPutCallBack)( (PCHAR)szEventField, (PCHAR)sNumber );
  135.             szCondition = (*lpfnGetCallBack)( szConditionField );
  136.         }
  137.     }
  138.     return lLoop;
  139. }
  140.  
  141. /******************************************************************************
  142. *
  143. * name          szExecuteString -- Send a command string to OV for execution
  144. *
  145. * description   Use this function to send a command to OV for execution.
  146. *
  147. * arguments     1.  PCHAR szCommand  -- the command to execute
  148. *               2.  OVCALLBACK_EXECUTESTRING lpfnCallBack -- callback fn
  149. *               3.  PCHAR sAnswerBuffer -- place for the answer
  150. *
  151. * return        PCHAR -- result string
  152. *
  153. * register      @REGISTER("@EXECUTE","CCnF","""CommandToExecute""",
  154. *                   "ovloops.dll","szExecuteString",1)
  155. *
  156. ******************************************************************************/
  157.  
  158. PCHAR EXPENTRY szExecuteString(
  159.     PCHAR szCommand,
  160.     OVCALLBACK_EXECUTESTRING lpfnCallBack,
  161.     PCHAR sAnswerBuf )
  162. {
  163.     PCHAR szResult;
  164.     szResult = (*lpfnCallBack)( szCommand, sAnswerBuf, 4096, 0 );
  165.     if ( !szResult )
  166.     {
  167.         szResult = ""; // Return something
  168.     }
  169.     return szResult;
  170. }
  171.  
  172.